package com.mc.api.service.impl;

import com.mc.api.domain.CltResult;
import com.mc.api.domain.LabAuthenticate;
import com.mc.api.mapper.CltResultMapper;
import com.mc.api.mapper.LabAuthenticateMapper;
import com.mc.api.service.ILabAuthenticateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class LabAuthenticateServiceImpl implements ILabAuthenticateService{
        @Autowired
        private LabAuthenticateMapper labAuthenticateMapper;

        @Autowired
        private CltResultMapper cltResultMapper;

        /**
         * 查询鉴定
         *
         * @param authenticateId 鉴定 ID
         * @return 鉴定
         */
        @Override
        public LabAuthenticate selectLabAuthenticateById(String authenticateId)
        {
            return labAuthenticateMapper.selectLabAuthenticateById(authenticateId);
        }

        /**
         * 查询鉴定 列表
         *
         * @param labAuthenticate 鉴定
         * @return 鉴定
         */
        @Override
        public List<LabAuthenticate> selectLabAuthenticateList(LabAuthenticate labAuthenticate)
        {
            return labAuthenticateMapper.selectLabAuthenticateList(labAuthenticate);
        }

        /**
         * 新增鉴定
         *
         * @param labAuthenticate 鉴定
         * @return 结果
         */
        @Override
        public int insertLabAuthenticate(LabAuthenticate labAuthenticate)
        {

            CltResult cltResult= cltResultMapper.selectCltResultById(labAuthenticate.getCltId());
            if(cltResult.getIsAuthenticate().equals("0")){
                    cltResultMapper.updateIsAuthenticate(labAuthenticate.getCltId());
            }
            return labAuthenticateMapper.insertLabAuthenticate(labAuthenticate);
        }

        /**
         * 修改鉴定
         *
         * @param labAuthenticate 鉴定
         * @return 结果
         */
        @Transactional
        @Override
        public int updateLabAuthenticate(LabAuthenticate labAuthenticate)
        {
            cltResultMapper.updateIsAuthenticate(labAuthenticate.getCltId());
            return labAuthenticateMapper.updateLabAuthenticate(labAuthenticate);
        }
}
